<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/inc/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>授权角色给实体</title>
<%@ include file="/inc/head.jsp"%>
</head>
<script type="text/javascript">
	var submitForm = function($dialog, $grid, $pjq) {
		if ($('form').form('validate')) {
			var url;
			if ($(':input[name="id"]').val().length > 0) {
				url = sy.contextPath + '/sys/auth/update';
			} else {
				url = sy.contextPath + '/sys/auth/user_group/create';
			}
			$.post(url, sy.serializeObject($('form')), function(result) {
				if (result.success) {
					$grid.datagrid('load');
					$dialog.dialog('destroy');
				} else {
					$pjq.messager.alert('提示', result.msg, 'error');
				}
			}, 'json');
		}
	};
</script>
<body>
	<form:form id="editForm" method="post" commandName="m" cssClass="form">
		<form:hidden path="type" />
		<fieldset>
			<legend>${type.info}信息</legend>
			<table class="table" style="width: 100%;">
				<tr>
					<th>编号</th>
					<td><input name="id" value="${m.id}" readonly="readonly" /></td>
				</tr>
				<c:if test="${op ne '新增'}">
					<tr>
						<c:if test="${m.type eq 'user'}">
							<th>用户信息</th>
							<td><sys:showUsername id="${m.userId}" /> <form:hidden
									path="userId" /></td>
						</c:if>
						<c:if test="${m.type eq 'user_group'}">
							<th>用户分组</th>
							<td><sys:showGroupName id="${m.groupId}" /> <form:hidden
									path="groupId" /></td>
						</c:if>
					</tr>
				</c:if>
				<c:if test="${op eq '新增'}">
					<tr>
						<c:if test="${m.type eq 'user'}">
							<th>用户ID（批量）</th>
							<td><select name="userIds" class="easyui-combogrid"
								style="width: 250px"
								data-options="
			panelWidth: 500,
			multiple: true,
			idField: 'id',
			textField: 'userName',
			url: '${ctx}/sys/user/0/0',
			method: 'post',
			pagination : true,
			pageSize : 50,
			columns: [[
				{field:'id',checkbox:true},
				{field:'username',title:'登录ID',width:120},
				{field:'fullName',title:'用户姓名',width:80,align:'right'},
				{field:'status',title:'状态',width:60,align:'center'}
			]],
			fitColumns: true
		">
							</select></td>
						</c:if>
						<c:if test="${m.type eq 'user_group' }">
							<th>分组编号(批量)</th>
							<td>
								<ul>
									<c:forEach items="${userGroups}" var="g">
										<li><input type="checkbox" name="groupIds"
											value="${g.id}">${g.name}</li>
									</c:forEach>
								</ul>
							</td>
						</c:if>
					</tr>
				</c:if>
			</table>
		</fieldset>
		<fieldset>
			<legend>角色信息</legend>
			<table width="100%">
				<c:forEach items="${roles}" var="r">
					<tr>
						<c:if test="${not esfn:in(m.roleIds, r.id)}">
							<td><input type="checkbox" name="roleIds" value="${r.id}"
								title="${r.description}">${r.name}[${r.role}]</td>

						</c:if>
						<c:if test="${esfn:in(m.roleIds, r.id)}">
							<td><input type="checkbox" checked="checked" name="roleIds"
								value="${r.id}" title="${r.description}">${r.name}[${r.role}]</td>
						</c:if>
					</tr>
				</c:forEach>
			</table>
		</fieldset>
	</form:form>
</body>
</html>